# Some variables are followed by these abbreviations
# fct = Factor, ordered, seven levels
# cat = Factor, unordered, three levels
# bin = Factor, dummy
# num = Numeric, dummy

# Confidence in Attribution ----------------------------------------------------
df$confidence_ord <- convert_confidence(df$confidence, to = "ordered")
df$confidence_cat <- convert_confidence(df$confidence, to = "categorical")
df$confidence_bin <- convert_confidence(df$confidence, to = "dummy")

# Support for Retribution ------------------------------------------------------
df$do_nothing <- factor(df$do_nothing, levels = c(0, 1), 
                        labels = c("Do not support", "Support"))

df$do_condemn <- factor(df$do_condemn, levels = c(0, 1), 
                        labels = c("Do not support", "Support"))

df$do_sanctions <- factor(df$do_sanctions, levels = c(0, 1), 
                          labels = c("Do not support", "Support"))

df$do_cyberespionage <- factor(df$do_cyberespionage, levels = c(0, 1), 
                               labels = c("Do not support", "Support"))

df$do_powergrid <- factor(df$do_powergrid, levels = c(0, 1), 
                            labels = c("Do not support", "Support"))

df$do_cyberattack <- factor(df$do_cyberattack, levels = c(0, 1), 
                            labels = c("Do not support", "Support"))

df$do_airstrikes <- factor(df$do_airstrikes, levels = c(0, 1), 
                           labels = c("Do not support", "Support"))

df$do_rank <- dplyr::case_when(df$do_cyberattack == "Support" ~ 5,
                               df$do_powergrid == "Support" ~ 4,
                               df$do_cyberespionage == "Support" ~ 3,
                               df$do_sanctions == "Support" ~ 2,
                               df$do_condemn == "Support" ~ 1,
                               df$do_nothing == "Support" ~ 0,
                               .default = NA)

df$support <- factor(df$do_rank,
                     levels = c(0, 1, 2, 3, 4, 5, NA), 
                     labels = c("Nothing", 
                                "Condemn", 
                                "Sanctions", 
                                "Cyberespionage", 
                                "Cyberattack Pwr. Grid",
                                "Cyberattack Govt."), 
                     ordered = TRUE)
                        
df$support_ord <- ordered(df$support)

df$support_cat <- ifelse(df$do_rank <= 3, 0, ifelse(df$do_rank == 4, 1, 2)) |>
  factor(levels = c(0, 1, 2), labels = c("De-escalation", "Proportional", "Escalation")) |>
  stats::relevel(ref = "De-escalation")

df$support_bin <- ifelse(df$do_rank < 3, 0, 1) |>
  factor(levels = c(0, 1), labels = c("De-escalation", "Retaliation")) |>
  stats::relevel(ref = "De-escalation")

# Support for Multilateral Action ----------------------------------------------
df$un_nothing <- factor(df$unsc_do_nothing, levels = c(0, 1), 
                             labels = c("Do not support", "Support"))

df$un_condemn <- factor(df$unsc_do_condemn, levels = c(0, 1), 
                             labels = c("Do not support", "Support"))

df$un_sanction <- factor(df$unsc_do_sanctions, levels = c(0, 1), 
                               labels = c("Do not support", "Support"))

df$un_force <- factor(df$unsc_do_force, levels = c(0, 1), 
                           labels = c("Do not support", "Support"))

df$un_rank <- dplyr::case_when(df$un_force == "Support" ~ 3,
                               df$un_sanction == "Support" ~ 2,
                               df$un_condemn == "Support" ~ 1,
                               df$un_nothing == "Support" ~ 0,
                               .default = NA)
                                 
df$unsc <- factor(df$unsc_rank,
                  levels = c(0, 1, 2, 3, NA),
                  labels = c("Nothing", 
                             "Condemn", 
                             "Sanctions", 
                             "Force"),
                  ordered = TRUE)

df$unsc_ord <- ordered(df$unsc)

# Treatment Variables ----------------------------------------------------------
df$endorsement <- factor(df$endorsement, levels = c(0, 1, 2), 
                         labels = c("None", "EU", "US"))

df$disavowal <- factor(df$disavowal, levels = c(0, 1),
                       labels = c("Israel", "Iran")) |>
  stats::relevel(ref = "Iran")

df$accusation <- ifelse(df$disavowal == "Iran", "Israel", "Iran") |>
  as.factor()

df$interaction <- interaction(df$accusation, df$endorsement)

treatments <- c("endorsement", "accusation")
interactions <- "endorsement:accusation"


# Pre-existing images ----------------------------------------------------------
df$iran <- rate_feelings(df$rate_iran, type = "all")
df$iran_imputed <- rate_feelings(df$rate_iran, type = "imputed")

df$israel <- rate_feelings(df$rate_israel, type = "all")
df$israel_imputed <- rate_feelings(df$rate_israel, type = "imputed")

df$eu <- rate_feelings(df$rate_eu, type = "all")
df$eu_imputed <- rate_feelings(df$rate_eu, type = "imputed")

countries <- c("iran", "israel", "eu")
countries_imputed <- c("iran_imputed", "israel_imputed", "eu_imputed")

